<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<style type="text/css">
.ui-datepicker {
	font-size: 13px;
	width: 180px;
}
.ui-datepicker select.ui-datepicker-month {
	width: 30%;
	font-size: 11px;
}
.ui-datepicker select.ui-datepicker-year {
	width: 40%;
	font-size: 11px;
}
</style>
<script type="text/javascript">
$(function() {
	var startM;
	var startD;
	$("#startDatepicker").datepicker({
    	dateFormat:'yy.mm.dd',
    	startDate:new Date(),
    	/* minDate:'2014-11-20', // 날짜 선택 최소값
    	maxDate:'2014-11-26', // 날짜 선택 최대값 */
    	selectOtherMonths:true, // 다른 달 선택가능
    	dayNames: ['월요일', '화요일', '수요일', '목요일', '금요일', '토요일', '일요일'],
        dayNamesMin: ['월', '화', '수', '목', '금', '토', '일'], 
        monthNamesShort: ['1','2','3','4','5','6','7','8','9','10','11','12'],
        monthNames: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
		onSelect:function(dateText, inst){
			var dateArr = dateText.split(".");
			startM=dateArr[1];
			startD=dateArr[2];
		}
    });
	var endM;
	var endD;
	$("#endDatepicker").datepicker({
    	dateFormat:'yy.mm.dd',
    	startDate:'2014.11.23',
    	selectOtherMonths:true, // 다른 달 선택가능
    	dayNames: ['월요일', '화요일', '수요일', '목요일', '금요일', '토요일', '일요일'],
        dayNamesMin: ['월', '화', '수', '목', '금', '토', '일'], 
        monthNamesShort: ['1','2','3','4','5','6','7','8','9','10','11','12'],
        monthNames: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
        onSelect:function(dateText, inst){
			var dateArr = dateText.split(".");
			endM=dateArr[1];
			endD=dateArr[2];
		}
    });
	$("#cinemaSelect").change(function(){
		$.ajax({
			type:"post",
			url:"${initParam.root}admin/checkCinema.do",
			data:"cinemaNo="+$(this).val()+"&movieNo=${requestScope.allInfoMap.movieContent.movieNo }",
			success:function(jsonData){
				if(jsonData==true){
					alert("상영 리스트에 선택한 영화관이 존재합니다!");
					$("form[name=writeShowingForm]")[0].reset();
				}
			}
		});
	});
	$("form[name=writeShowingForm]").submit(function(){
		var cinemaNoComp=$("#cinemaSelect").val();
		var startDateComp=$("input[name=startDate]").val();
		var endDateComp=$("input[name=endDate]").val();
		if(cinemaNoComp==""){
			alert("상영 영화관을 선택하세요!");
			return false;
		}
		if(startDateComp==""){
			alert("상영 시작일을 입력하세요!");
			return false;
		}
		if(endDateComp==""){
			alert("상영 종료일을 입력하세요!");
			return false;
		}
		if(!((startM==endM&&startD<=endD)||startM<endM)){
			alert("상영 시작일은 상영 종료일보다 전에 있어야 합니다!");
			$(this)[0].reset();
			return false;
		}
	});
});
</script>
<h3>상영영화 - 등록</h3>
<hr align="left" width="150">
<center>
<!-- 상영 등록 폼 -->
<form action="${initParam.root }admin/allShowingWrite.do" method="post" name="writeShowingForm">
<table class="movieContent">
	<tr>
		<td colspan="4">상영 정보 등록</td>
	</tr>
	<tr>
		<td rowspan="2">
			<select class="select" name="movieVO.movieNo" id="movieSelect">
				<option value="">--영화 선택--</option>
				<c:forEach items="${requestScope.allInfoMap.movieList }" var="movieVO">
					<option name="movieVO.movieNo" value="${movieVO.movieNo }">${movieVO.title }</option>
				</c:forEach>	
			</select>
		</td>
		<td rowspan="2">
			<select class="select" name="cinemaVO.cinemaNo" id="cinemaSelect">
				<option value="">--영화관 선택--</option>
				<c:forEach items="${requestScope.allInfoMap.cinemaList }" var="cinemaVO">
					<option value="${cinemaVO.cinemaNo }">${cinemaVO.name }</option>
				</c:forEach>	
			</select>
		</td>
		<td>
			상영 시작일: <input type="text" name="startDate" id="startDatepicker" readonly>
		</td>
		<td rowspan="2">
			<input type="submit" id="writeShowingBtn" value="등록">
		</td>
	</tr>
	<tr>
		<td>
			상영 종료일: <input type="text" name="endDate" id="endDatepicker" readonly>
		</td>
	</tr>
</table>
</form>
</center>